<!-- 生产带班记录 -->
<template>
  <base-breadcrumb :title="$route.meta.title">
    <a-row
      :gutter="10"
      class="page-height"
    >
      <!-- 树搜索 -->
      <a-col
        :span="6"
        class="permission-collapsed"
        :class="{ 'permission-tree-collapsed': collapsed }"
      >
        <a-card
          :style="{ border: collapsed ? 'none' : 'border: 1px solid #e8e8e8' }"
          class="page-height-tree"
        >
          <title-name title="组织架构" />
          <PermissionTreeOrganization
            :collapsed.sync="collapsed"
            @select="handleSelect"
          />
        </a-card>
      </a-col>
      <a-col
        :span="18"
        class="permission-collapsed page-height-list-wrapper"
        :style="collapsed ? 'width:calc(100% - 10px)' : ''"
      >
        <!-- 搜索 -->
        <searchData
          :search-data="searchOption"
          @search="search"
        />
        <a-card class="page-height-list">
          <!-- <title-name title="生产带班记录" /> -->
          <div class="table-operator">
            <a-button
              type="primary"
              @click="jumpHandler('add')"
              v-btnPermission="[{code:'seex_pm_043_add_02',ident:'prma_seex'},{code:'buco_pm_043_add_02',ident:'prma_buco'}]"
            >新增</a-button>
          </div>
          <div class="pub-table-select-count">
            <a-icon
              type="info-circle"
              theme="twoTone"
            />
            <span style="margin-right: 12px">总数量：<span class="totalNum">{{ totalSize }}个</span>
            </span>
          </div>
          <list-table
            :defaultLoad="false"
            ref="table"
            size="default"
            rowKey="id"
            :columns="columns"
            :request="loadData"
            :alert="true"
            show-size-changer
            show-quick-jumper
            :show-pagination="true"
            :loadPage="{
              currentPage: 'pageNum',
              totalSize: 'total',
              data: 'list'
            }"
          >
            <span
              slot="serial"
              slot-scope="text, record, index"
            >{{ index + 1 }}</span>
            <!-- 状态 -->
            <span
              slot="checkStatus"
              slot-scope="text, recode"
            >
              {{ recode.status == 1 ? '已提交' : '待提交' }}
            </span>
            <span
              slot="action"
              slot-scope="text, recode"
            >
              <a
                v-btnPermission="[{code:'seex_pm_043_loo_01',ident:'prma_seex'},{code:'buco_pm_043_loo_01',ident:'prma_buco'}]"
                @click="jumpHandler('look', recode.id)"
              >查看</a>
              <template v-if="(recode.status == 0 && visibleBtn(recode)) && hideBuquBtn()">
                <span>
                  <a-divider type="vertical" />
                  <a @click="jumpHandler('edit', recode.id)">编辑</a>
                </span>
                <span>
                  <a-popconfirm
                    placement="top"
                    ok-text="确定"
                    cancel-text="取消"
                    @confirm="deleteItemHandler(recode)"
                  >
                    <template slot="title">
                      <p>请确认是否要删除</p>
                    </template>
                    <span>
                      <a-divider type="vertical" />
                      <a>删除</a>
                    </span>
                  </a-popconfirm>
                </span>
              </template>
            </span>
          </list-table>
        </a-card>
      </a-col>
    </a-row>
  </base-breadcrumb>
</template>

<script>
import PermissionTreeOrganization from '@/components/businessComponents/PermissionTreeOrganization'
import { searchOption, columns } from './mode'
import { getPageProjectProductionShiftRecord, deleteByPrimaryKey } from '@/api/project/productionShiftRecord'

export default {
  name: 'productionShiftRecord',
  data() {
    return {
      // 收缩展开树
      collapsed: false,
      //组织架构选中项
      select: null,
      totalSize: '',
      // 查询参数
      queryParam: {},
      searchOption,
      columns,
      loadData: (p) => {
        const obj = {}
        // if (!this.select) {
        //   this.$message.warning('请选择公司')
        //   return
        // }
        // 二级-分公司id
        if (this.select?.tageCode === 'BC') {
          obj.branchId = this.select.orgId
        }
        // 三级-项目id
        if (this.select?.tageCode === 'PD') {
          obj.projectId = this.select.projectId
        }
        p.pageNum = p.pageNo
        delete p.pageNo
        let searchData = Object.assign(p, { param: { ...obj, ...this.queryParam } })
        return getPageProjectProductionShiftRecord(searchData).then((res) => {
          this.totalSize = res.data.total
          res.data.list.map((v) => {
            // v.deleteLoading = false
          })
          return {
            code: 200,
            ...res.data,
            data: res.data.list,
            currentPage: res.data.pageNum,
            totalSize: res.data.total,
            totalPage: res.data.firstPage
          }
        })
      }
    }
  },

  components: { PermissionTreeOrganization },

  computed: {},

  created() {},

  mounted() {},

  methods: {
    // 删除生产记录
    deleteItemHandler(row) {
      deleteByPrimaryKey({ id: row.id })
        .then((res) => {
          this.$refs.table.refresh(true)
        })
        .catch(() => {})
    },
    // list得item是不是本人
    visibleBtn({ creatorId }) {
      return JSON.parse(sessionStorage.getItem('ycloud-user_info')).id == creatorId
    },
    /**
     * @description 编辑页
     * @params {*} type: add:新增 look:查看 edit：编辑
     * @params {*} id:带班记录id
     */
    jumpHandler(type, id) {
      let query = { type }
      id && (query.id = id)
      this.$router.push({
        path: '/project/productionShiftRecord/update',
        query
      })
    },
    /**
     * @description: 树选中
     * @param {object} node 节点对象
     * @return {void}
     */
    handleSelect(node) {
      this.select = node
      this.search()
    },
    search(val = {}) {
      this.queryParam = {}
      if (val) {
        val.creatorName && (this.queryParam.creatorName = val.creatorName)
        val.createTimeStart && (this.queryParam.startTime = this.moment(val.createTimeStart).format('YYYY-MM-DD'))
        val.createTimeEnd && (this.queryParam.endTime = this.moment(val.createTimeEnd).format('YYYY-MM-DD'))
      }
      this.$refs.table.refresh(true)
    }
  }
}
</script>

<style scoped>
</style>
